/**      
 * @file			readingTxtFile.cpp
 * @description			Reads from a text file, "Patterson_James_Step_on_a_Crack.txt",
 *				and counts the words in the file. A word is any character that is 
 *				between two spaces.
 * @course			CSCI 123 Section 00000
 * @assignment 
 * @date			mm/dd/yyyy
 * @author			Brad Rippe (00000000) brippe@fullcoll.edu
 * @version			1.0
 */
#include <iostream>		// cin and cout
#include <cstdlib>		// exit()
#include <fstream>		// ifstream
#include <cctype>		// isspace()
using namespace std;

/**
 * @return zero if the application executes successfully
 */
int main() {
	int words = 0;
	ifstream inFile;
	
	inFile.open("Patterson_James_Step_on_a_Crack.txt");
	if(inFile.fail()) {
		cout << "Couldn't open Patterson_James_Step_on_a_Crack.txt file!\n";
		exit(1);
	}
	char ch;
	do {
		inFile.get(ch);
		if(isspace(ch)) {
			words++;
		}
		//cout << ch;

		// inFile.putback(ch);
		// putback returns the character to the input stream
		// if this call is placed inside the loop
		// the loop enters an infinite loop because it will
		// never read any further than the first character
	} while (!inFile.eof());

	cout << "Patterson_James_Step_on_a_Crack.txt contains " << words;
	cout << " words.\n";

	return 0;
}

